import config
from api.login import LoginAPI
from api.dept import DeptAPI
from common.assertutil import common_assert

class TestDept:
    token666 = None
    dept_id = None
    def setup_class(self):
        self.login_api = LoginAPI()
        self.dept_api = DeptAPI()

        response = self.login_api.login(config.login_data)
        TestDept.token666 = response.json().get("data")
        print(TestDept.token666)


    def test01_get_dept_list(self):
        response = self.dept_api.get_dept_list(TestDept.token666)
        print(response.json())

        # assert response.status_code == 200
        # assert response.json().get("success") is True
        # assert response.json().get("code") == 10000
        # assert "成功" in response.text
        common_assert(response)

    def test02_insert_dept(self):
        response = self.dept_api.insert_dept(config.insert_data,TestDept.token666)
        print(response.json())

        # assert response.status_code == 200
        # assert response.json().get("success") is True
        # assert response.json().get("code") == 10000
        # assert "成功" in response.text
        common_assert(response)

        TestDept.dept_id = response.json().get("data").get("id")
        print(TestDept.dept_id)
    def test03_select_dept(self):
        response = self.dept_api.select_dept(TestDept.dept_id,TestDept.token666)
        print(response.json())
        common_assert(response)
    def test04_update_dept(self):
        response = self.dept_api.update_dept(TestDept.dept_id,config.update_data,TestDept.token666)
        print(response.json())
        common_assert(response)
    def test05_delete_dept(self):
        response = self.dept_api.delete_dept(TestDept.dept_id, TestDept.token666)
        print(response.json())
        common_assert(response)
